package com.webull.information.center.common.util;

import javax.jms.Topic;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import com.webull.framework.util.UtilJson;
import com.webull.information.client.model.parm.NewsUpdateEvent;

/**
 * @author shimingjun
 * @date 2016年11月21日 下午2:28:51
 * @version 1.0
 * @since JDK 1.8
 */
@Component
public class MessageSender {
	protected final Logger logger = LogManager.getLogger(getClass());
	private @Autowired JmsTemplate jmsTemplate;
	private @Autowired @Qualifier("infoNewsModifyTopic") Topic infoNewsModifyTopic;



	@Async
	public void sendModify(NewsUpdateEvent event) {
		if (event == null || event.getNewsId() == null) return;
		String json = UtilJson.writeValueAsString0(event);
		jmsTemplate.send(infoNewsModifyTopic, (session) -> {
			logger.info("发送档案变更通知：{}", json);
			return session.createTextMessage(json);
		});
	}
}